<template>
  <div class="areaWrap">
    <van-popup
      round
      v-model="showArea"
      :close-on-click-overlay="false"
      position="bottom"
      get-container="body"
      class="areaPopUp"
      :style="{ height: '50%' }"
    >
      <van-area
        :confirm-button-text="add"
        @confirm="confirmMet"
        :value="value"
        @cancel="closeMet"
        title="山西省"
        :area-list="areaList"
      />
    </van-popup>
  </div>
</template>
<script type="text/javascript">
import areaList from "./arealist.js";
import { getItem } from "../../util/storage.js";
import meteoroHomeApi from "../../service/home";
export default {
  data() {
    return {
      showArea: true,
      value: "",
      areaList: areaList,
    };
  },
  props: {
    add: {
      type: String,
      require: true,
    },

    arr: {
      type: Array,
      default: Array,
    },
  },

  mounted() {
    for (let key in this.areaList.county_list) {
      if (this.arr[1] == this.areaList.county_list[key]) {
        this.value = key;
      }
    }
  },
  // created() {
  //   console.log(this.arr);
  //   var username = getItem("username");
  //   let number;
  //   meteoroHomeApi.getPermissions().then((res) => {
  //     this.areaList = res;

  //     var city = "";
  //     let list = {
  //       ll01: "吕梁市",
  //       ty01: "太原市",
  //       dt01: "大同市",
  //       yq01: "阳泉市",
  //       cz01: "长治市",
  //       jc01: "晋城市",
  //       sz01: "朔州市",
  //       jz01: "晋中市",
  //       yc01: "运城市",
  //       xz01: "忻州市",
  //       lf01: "临汾市",
  //     };
  //     var city;
  //     for (let key in list) {
  //       if (key == username) {
  //         city = list[key];

  //         for (let key in this.areaList.city_list) {
  //           if (this.areaList.city_list[key] !== city) {
  //             delete this.areaList.city_list[key];
  //           } else {
  //             number = key;
  //           }
  //         }

  //         let strNumber = number.toString();
  //         let firstFourDigits = strNumber.substring(0, 4);
  //         let newCountyList = {};
  //         for (let [key, value] of Object.entries(this.areaList.county_list)) {
  //           if (key.startsWith(firstFourDigits)) {
  //             newCountyList[key] = value;
  //           }
  //         }

  //         this.areaList.county_list = newCountyList;
  //       }
  //     }

  //   });
  // },
  watch: {},
  components: {},
  methods: {
    closeMet() {
      this.$emit("closeEmit");
    },
    confirmMet(value) {
      this.value = value[2].code;

      this.$emit("confirmEmit", value);
    },
  },
};
</script>
<style type="text/css" lang="less"></style>
